import Cesium from 'cesium'
import type { BillboardController } from './utils'
import type { AxiosRequestConfig } from 'axios'
import type { DebouncedFunc } from 'lodash'

export type DataTypeKey = 'risk' | 'device' | 'event'

export interface PointCommonParams {
  // (必传)  2电子围栏  3圈选  4视图窗口 5类型查询
  queryType: number
  // 数量
  viewLimit?: number
  // 视窗
  viewNeLng?: number
  viewSwLng?: number
  viewNeLat?: number
  viewSwLat?: number
  // 电子围栏
  electronicFenceJson?: string
  // 区域编码
  districtCode?: string
  // 中心半径
  lng?: number
  lat?: number
  radius?: number
}

export interface RiskParamsTypes extends PointCommonParams {
  // 板块
  block?: string[]
  // 跑道
  racetrack?: string
  // 子跑道
  subRacetrack?: string
  // 风险点类型
  riskPointTypeName?: string[]
}

export interface DeviceParamsTypes extends PointCommonParams {
  // 设备类型
  deviceTypeName?: string[]
}

export interface EventParamsTypes extends PointCommonParams {
  // 板块
  block?: string[]
  // 跑道
  racetrack?: string
  // 子跑道
  subRacetrack?: string
  // 事件类型
  eventType?: string[]
  // 处置状态
  eventStatus?: string[]
  // 开始时间
  happenTimeStart?: string
  // 结束时间
  happenTimeEnd?: string
}

export interface TypedBillboard {
  id: string
  // 类型
  type: string
  // 标签名
  label: string
  cesiumBillboard: Cesium.Billboard
  visible: boolean
  metadata?: Record<string, any>
}

export type ReturnBillboard = TypedBillboard | undefined

export type FieldMappingsKey = 'id' | 'type' | 'label' | 'jd' | 'wd' | 'height' | 'image'
export type FieldMappings = {
  [key in FieldMappingsKey]?: string
}

export type RequestParams = Record<string, any>

export type HookFn = (
  billboardController: BillboardController,
  iconMap: IconMap
) => {
  executeRequest: DebouncedFunc<(params: RequestParams) => void>
}

export type IconMap = Record<string, string>
export interface LayerConfig {
  params: RequestParams
  readonly billboardController: BillboardController
  readonly hook: HookFn
}

export interface RadarConfig {
  radius: number
  lng: number
  lat: number
  visible: boolean
}

export type RequestFn = (
  params: RequestParams,
  config: AxiosRequestConfig
) => Promise<{ data: any[] }>
